package com.example.demo;

import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.constant.ClassificationCategory;
import com.example.demo.mapper.*;
import com.example.demo.pojo.entity.QuestionClassification;
import com.example.demo.pojo.entity.QuestionLabel;
import com.example.demo.pojo.entity.Subject;
import lombok.RequiredArgsConstructor;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

@SpringBootTest
@RequiredArgsConstructor
public class selectPageBank {
    @Autowired
    private QuestionBankMapper questionBankMapper;
    @Autowired
    private QuestionCategoryMapper questionCategoryMapper;
    @Autowired
    private QuestionClassificationMapper questionClassificationMapper;
    @Autowired
    private QuestionLabelMapper questionLabelMapper;
    @Autowired
    private SubjectMapper subjectMapper;
    @Autowired
    private QuestionFileMapper questionFileMapper;

    @Test
    void mainSelectByLabel(){
        int subjectId=1; //前端参数的模拟
        //获得基本数据
        Subject subject=subjectMapper.selectById(subjectId);
        int labelId=subject.getLabelId();
        HashMap<Integer,Integer>hashMapRealNumber=new HashMap<>();
        HashMap<Integer,Integer>hashMapImageNUmber=new HashMap<>();

    }
    void selectRINumber(int labelId,HashMap<Integer,Integer>hashMapRealNumber,HashMap<Integer,Integer>hashMapImageNumber){
        QueryWrapper<QuestionLabel> questionLabelQuery=new QueryWrapper<>();
        String nodeIdRoot=labelId+"-";
        questionLabelQuery.likeRight("node_id",nodeIdRoot);
        List<QuestionLabel>questionLabelList=questionLabelMapper.selectList(questionLabelQuery);
        for(QuestionLabel questionLabelFor:questionLabelList){
            int labelIdFor=questionLabelFor.getId();
            String nodeIdFor=labelIdFor+"-";
            //查找实题目
            QueryWrapper<QuestionClassification>questionRealClassificationQueryWrapper=new QueryWrapper<>();
            questionRealClassificationQueryWrapper.eq("question_label_id",labelIdFor)
                    .eq("classification_category", ClassificationCategory.direct_classification)
                     .or()
                    .eq("classification_category",3)
                    .eq("question_label_id",labelIdFor);
            List<Integer>realQuestionIdList=questionClassificationMapper.selectList(questionRealClassificationQueryWrapper).stream().map(QuestionClassification::getQuestionBankId).collect(Collectors.toList());
            hashMapRealNumber.put(labelIdFor,realQuestionIdList.size());
            //查找虚题目
            QueryWrapper<QuestionClassification>questionImageClassificationQueryWrapper=new QueryWrapper<>();
            questionImageClassificationQueryWrapper
                    .likeRight("node_id",nodeIdFor)
                    .ne("classification_category",0);
            List<Integer>imageQuestionIdList=questionClassificationMapper.selectList(questionImageClassificationQueryWrapper).stream().map(QuestionClassification::getQuestionBankId).collect(Collectors.toList());
            hashMapImageNumber.put(labelIdFor,imageQuestionIdList.size());
        }
    }

}
